package com.github.yoojia.flow.at;

import com.sun.management.OperatingSystemMXBean;

import java.lang.management.ManagementFactory;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 陈小锅 (yoojiachen@gmail.com)
 * @since 1.0.0
 */
final class MemoryHandlerImpl implements AtHandler {

    @Override
    public String handle(String... args) {
        final OperatingSystemMXBean osb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        final Runtime runtime = Runtime.getRuntime();
        final Map<String, Object> data = new HashMap<>();
        data.put("mem_free", runtime.freeMemory());
        data.put("mem_total", runtime.totalMemory());
        data.put("mem_phy_free", osb.getFreePhysicalMemorySize());
        data.put("mem_phy_total", osb.getTotalPhysicalMemorySize());
        data.put("mem_swap", osb.getFreeSwapSpaceSize());
        return ATEvents.success(data);
    }
}
